package com.taotao.rest.dao;

import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

/**
 * @Package com.taotao.rest.dao
 * @Description:
 * @Author elwyn
 * @Date 2017/9/6 22:21
 * @Email elonyong@163.com
 */
public class JedisClientSingle implements JedisClient {
    @Autowired
    private JedisPool jedisPool;

    @Override
    public String get(String key) {
        Jedis resource = jedisPool.getResource();
        String s = resource.get(key);
        resource.close();
        return s;
    }

    @Override
    public String set(String key, String value) {
        Jedis resource = jedisPool.getResource();
        String s = resource.set(key, value);
        resource.close();
        return s;
    }

    @Override
    public String hget(String hkey, String key) {
        Jedis resource = jedisPool.getResource();
        String s = resource.hget(hkey, key);
        resource.close();
        return s;
    }

    @Override
    public long hset(String hkey, String key, String value) {
        Jedis resource = jedisPool.getResource();
        Long hset = resource.hset(hkey, key, value);
        resource.close();
        return hset;
    }

    @Override
    public long incr(String key) {
        Jedis resource = jedisPool.getResource();
        Long hset = resource.incr(key);
        resource.close();
        return hset;
    }

    @Override
    public long expire(String key, int second) {
        Jedis resource = jedisPool.getResource();
        Long expire = resource.expire(key, second);
        resource.close();
        return expire;
    }

    @Override
    public long ttl(String key) {
        Jedis resource = jedisPool.getResource();
        Long expire = resource.ttl(key);
        resource.close();
        return expire;
    }

    @Override
    public long del(String key) {
        Jedis resource = jedisPool.getResource();
        Long expire = resource.del(key);
        resource.close();
        return expire;
    }

    @Override
    public long hdel(String hkey, String key) {
        Jedis resource = jedisPool.getResource();
        Long expire = resource.hdel(hkey, key);
        resource.close();
        return expire;
    }
}
